package com.turnengine.client.local.error.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Local Trace.
 */
public class LocalTrace implements ILocalTrace, Comparable<ILocalTrace> {

	/** The id. */
	private String id = "";
	/** The datetime. */
	private long datetime = 0;
	/** The trace. */
	private String trace = "";

	/**
	 * Creates a new Local Trace.
	 */
	public LocalTrace() {
	}

	/**
	 * Creates a new Local Trace.
	 * @param id the id
	 * @param datetime the datetime
	 * @param trace the trace
	 */
	public LocalTrace(String id, long datetime, String trace) {
		setId(id);
		setDatetime(datetime);
		setTrace(trace);
	}

	/**
	 * Creates a new Local Trace.
	 * @param localTrace the local trace
	 */
	public LocalTrace(LocalTrace localTrace) {
		setId(localTrace.getId());
		setDatetime(localTrace.getDatetime());
		setTrace(localTrace.getTrace());
	}

	/**
	 * Creates a new Local Trace.
	 * @param iLocalTrace the i local trace
	 */
	public LocalTrace(ILocalTrace iLocalTrace) {
		setId(iLocalTrace.getId());
		setDatetime(iLocalTrace.getDatetime());
		setTrace(iLocalTrace.getTrace());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public String getId() {
		return id;
	}

	/**
	 * Returns the datetime.
	 * @return the datetime.
	 */
	public long getDatetime() {
		return datetime;
	}

	/**
	 * Returns the trace.
	 * @return the trace.
	 */
	public String getTrace() {
		return trace;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * Sets the datetime.
	 * @param datetime the datetime to set.
	 */
	public void setDatetime(long datetime) {
		this.datetime = datetime;
	}

	/**
	 * Sets the trace.
	 * @param trace the trace to set.
	 */
	public void setTrace(String trace) {
		this.trace = trace;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(577, 37);
		hash.append(id);
		hash.append(datetime);
		hash.append(trace);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof LocalTrace) {
			LocalTrace compare = (LocalTrace) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.datetime, compare.datetime);
			equals.append(this.trace, compare.trace);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ILocalTrace compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.datetime, compare.getDatetime());
		builder.append(this.trace, compare.getTrace());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		if (id != null) {
			string.append("id", id);
		}
		string.append("datetime", datetime);
		if (trace != null) {
			string.append("trace", trace);
		}
		return string.toString();
	}
}
